﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class TimeIntervalSelectionForm : Form
    {
        private const int MinimumStartHour = 6;
        private const int MaximumEndHour = 11;
        private const int DefaultStartHour = 6;
        private const int DefaultEndHour = 9;

        public int selectedStartHour = 6;
        public int selectedEndHour = 9;

        public TimeIntervalSelectionForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.selectedStartHour = Int32.Parse(comboBox1.Text);
            this.selectedEndHour = Int32.Parse(comboBox2.Text);
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }

        private void TimeIntervalSelectionForm_Load(object sender, EventArgs e)
        {
            for (int i = DefaultStartHour; i < MaximumEndHour; i++)
            {
                comboBox1.Items.Add(String.Format("{0}", i));
            }

            comboBox1.SelectedIndex = 0;

            for (int i = DefaultEndHour; i <= MaximumEndHour; i++)
            {
                comboBox2.Items.Add(string.Format("{0}", i));
            }

            comboBox2.SelectedIndex = 0;

            this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int startHour = Int32.Parse(comboBox1.Text);

            comboBox2.Items.Clear();

            for (int i = startHour + 1; i <= MaximumEndHour; i++)
            {
                comboBox2.Items.Add(string.Format("{0}", i));
            }

            comboBox2.SelectedIndex = 0;
        }
    }
}
